import os
from loguru import logger

class InputProcessor:
    @staticmethod
    def process_input(source_type: str, data: dict) -> dict:
        user_input = ""
        file_context = ""

        if source_type == "cli":
            user_input = data.get("prompt", "")
            file_path = data.get("file_path")
            if file_path:
                try:
                    with open(file_path, 'r', encoding='utf-8') as f:
                        file_context = f.read()
                except FileNotFoundError:
                    logger.error(f"Error: File not found at {file_path}")
                except Exception as e:
                    logger.error(f"An error occurred while reading file: {e}")
        elif source_type == "web":
            user_input = data.get("prompt", "")
            # Web input currently doesn't support file context directly, but could be extended
        elif source_type == "interactive_cli":
            user_input = data.get("prompt", "")
            # Interactive CLI doesn't have file context in this simple setup
        else:
            logger.warning(f"Unknown source type: {source_type}")

        return {"user_input": user_input, "file_context": file_context}
